package com.hdjk.view.activity.personalcenter;

import android.content.Intent;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;

import com.hdjk.view.R;
import com.hdjk.view.adapter.RedeemSuccessAdapter;
import com.hdjk.view.config.Constant;
import com.hdjk.view.entity.SellResult;
import com.lst.projectlib.base.BaseActivity;

import java.util.List;

/**
 * Created by Administrator on 2017/11/21.
 */

public class RedeemSuccessActivity extends BaseActivity implements View.OnClickListener {

    private com.lst.projectlib.component.CustomView.TopTitleBar ttb_title_bar;
    private ListView lv_data_list;
    private RedeemSuccessAdapter mAdapter;
    private Button tv_ok;

    @Override
    protected void initView(Bundle savedInstanceState) {
        setContentView(R.layout.activity_redeem_success);
        ttb_title_bar = (com.lst.projectlib.component.CustomView.TopTitleBar) findViewById(R.id.ttb_title_bar);
        ttb_title_bar.findViewById(R.id.tvNavBack).setOnClickListener(this);

        lv_data_list = (ListView) findViewById(R.id.lv_data_list);
        tv_ok = (Button) findViewById(R.id.tv_ok);
        tv_ok.setOnClickListener(this);
    }

    @Override
    protected void initData() {
        List<SellResult> sellResults = (List<SellResult>) getIntent().getSerializableExtra("sellResults");
        mAdapter = new RedeemSuccessAdapter(this);
        mAdapter.setDataList(sellResults);
        lv_data_list.setAdapter(mAdapter);

        Intent intent = new Intent(Constant.INTENT_FILTER_STRING_AFTER_REDEEM_SUCCESS);
        sendBroadcast(intent);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_ok:
                success();
                break;
            case R.id.tvNavBack:
                success();
                break;
        }
    }

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
            success();
        }
        return super.onKeyDown(keyCode, event);
    }

    private void success() {
        setResult(1002);
        back();
    }
}